package com.yf.controller.admin;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.entity.StockEntity;
import com.yf.service.StockService;
import com.yf.response.R;
import com.yf.consts.DaoConst;


/**
 * 库存Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Thu Aug 16 13:36:44 CST 2018
 */
@RestController
@RequestMapping("/stock")
public class StockController {
    @Autowired
    private StockService stockService;

    /**
     * 列表库存
     */
    @RequestMapping("/list")
    @RequiresPermissions("stock:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<StockEntity> stockList = stockService.queryList(params);
        return R.ok(new PageInfo(stockList));
    }

    /**
     * 查看库存
     */
    @SysLog("查看库存")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("stock:info")
    public R info(@PathVariable("id") Long id) {
        StockEntity stock = stockService.get(id);

        return R.ok(stock);
    }

    /**
     * 保存库存
     */
    @SysLog("保存库存")
    @RequestMapping("/save")
    @RequiresPermissions("stock:save")
    public R save(StockEntity stock) {
        stockService.save(stock);

        return R.ok(stock);
    }

    /**
     * 修改库存
     */
    @SysLog("修改库存")
    @RequestMapping("/update")
    @RequiresPermissions("stock:update")
    public R update(StockEntity stock) {
        stockService.update(stock);

        return R.ok(stock);
    }

    /**
     * 删除库存
     */
    @SysLog("删除库存")
    @RequestMapping("/delete")
    @RequiresPermissions("stock:delete")
    public R delete(@RequestBody Long[]ids) {
        stockService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有库存
     */
    @SysLog("所有库存")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<StockEntity> stockList = stockService.queryList(params);

        return R.ok(stockList);
    }

    /***********自定义开始***********/
}
